package com.ssm.subject.infra.basic.service.impl;

import com.alibaba.fastjson.JSON;
import com.ssm.subject.infra.basic.entity.SubjectMapping;
import com.ssm.subject.infra.basic.mapper.SubjectMappingDao;
import com.ssm.subject.infra.basic.service.SubjectMappingService;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 题目分类关系表(SubjectMapping)表服务实现类
 *
 * @author makejava
 * @since 2024-11-27 20:47:35
 */
@Service("subjectMappingService")
@Log4j2
public class SubjectMappingServiceImpl implements SubjectMappingService {
    @Resource
    private SubjectMappingDao subjectMappingDao;

    /**
     * 新增数据
     *
     * @param subjectMapping 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectMapping insert(SubjectMapping subjectMapping) {
        this.subjectMappingDao.insert(subjectMapping);
        return subjectMapping;
    }

    /**
     * 修改数据
     *
     * @param subjectMapping 实例对象
     * @return 实例对象
     */
    @Override
    public int update(SubjectMapping subjectMapping) {
        return this.subjectMappingDao.update(subjectMapping);
    }

    /**
     * 根据分类id查询(写sql时进行去重，不同题目使用的小分类和标签是一样的)
     * @param subjectMapping
     * @return
     */
    @Override
    public List<SubjectMapping> queryByLabelId(SubjectMapping subjectMapping) {
        return subjectMappingDao.queryByLabelId(subjectMapping);
    }

    /**
     * 批量插入
     * @param subjectMappingList
     */
    @Override
    public void batchInsert(List<SubjectMapping> subjectMappingList) {
        if(log.isInfoEnabled()) {
            log.info("SubjectMappingService.add.subjectMappingList:{}", JSON.toJSONString(subjectMappingList));
        }
        this.subjectMappingDao.batchInsert(subjectMappingList);
    }


}
